<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #root {
            width: 1400px;
            height: 100px;
            background-color: rgb(193, 118, 255);
            margin: 100px auto;
            /*position: relative;*/
            /*display: flex;*/
        }
        
        li {
            list-style: none;
            color: white;
            float: left;
            height: 100px;
            font-size: 30px;
            line-height: 100px;
            width: 120px;
            /*margin: 0 10px;*/
            text-align: center;
        }
        
        ul {
            z-index: 3;
            position: relative;
            background-color: red;
        }
        
        .bj {
            background-color: #006600;
        }
        
        #hua {
            position: absolute;
            height: 100px;
            width: 100px;
            background-color: #006600;
            margin-left: 50px;
            z-index: 0;
            transition: all 1s;
        }
    </style>
</head>

<body>
    <div id="root">
        <ul>
            <li class="bj">首页</li>
            <li>国内</li>
            <li>国际</li>
            <li>财经</li>
            <li>娱乐</li>
            <li>体育</li>
            <li>互联网</li>
            <li>科技</li>
            <li>游戏</li>
            <li>女人</li>
            <li>汽车</li>

        </ul>
        <div id="hua">

        </div>
    </div>


</body>

</html>
<script>
    var li1 = document.getElementsByTagName('li');
    var hua = document.getElementById('hua');

    console.log(li1);
    var index = 0;
    for (var i = 0; i < li1.length; i++) {
        li1[i].onclick = function() {
            //      	console.log(i);
            for (var j = 0; j < li1.length; j++) {

                if (this == li1[j]) {
                    index = j;
                    li1[j].className = 'bj';
                } else {
                    li1[j].className = '';
                }
            }
        }
        li1[i].onmouseenter = function() {

            for (var j = 0; j < li1.length; j++) {

                if (this == li1[j]) {

                    hua.style.transform = "translateX(" + (j * 120) + "px)";
                }
            }
        }
        li1[i].onmouseleave = function() {

            hua.style.transform = "translateX(" + index * 120 + "px)";
        }
    }
</script>